﻿using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace superSocketApi.Controllers
{
	[EnableCors("cors")]
	[Route("api/[controller]")]
	[ApiController]
	public class ServerController : ControllerBase
	{
		[HttpGet]
		[Route("Clients")]
		public async Task<IActionResult> ClientList1()
		{
			return await Task.Run(() => { return Ok(Global.ServerInfoFun.SessionList1()); });
		}

		//[HttpGet]
		//[Route("Clients/WebSocket")]
		//public async Task<IActionResult> ClientList2()
		//{
		//	return await Task.Run(() => { return Ok(Global.ServerInfoFun.SessionList2()); });
		//}

		[HttpPost]
		[Route("Client/{sessionId}/SendHsmsData")]
		public async Task<IActionResult> SendHsmsData(string sessionId, byte stream, byte function, [FromBody] string bodyData)
		{
			return await Task.Run(() => { return Ok(Global.ServerInfoFun.SendHsmsDataBySessionId(sessionId, stream, function, bodyData)); });
		}

		[HttpPost]
		[Route("Client/{sessionId}/SendHsmsCmd")]
		public async Task<IActionResult> SendHsmsCmd(string sessionId, byte stype)
		{
			return await Task.Run(() => { return Ok(Global.ServerInfoFun.SendHsmsCmdBySessionId(sessionId, stype)); });
		}


		[HttpPost]
		[Route("Client/{sessionId}/SendString")]
		public async Task<IActionResult> SendString(string sessionId, [FromBody] string sendData)
		{
			return await Task.Run(() => { return Ok(Global.ServerInfoFun.SendStringBySessionId(sessionId, sendData)); });
		}
		/// <summary>
		/// 发送十六进制数据
		/// </summary>
		/// <param name="sessionId">连接的Seesion</param>
		/// <param name="sendData">发送的十六进制数据,"01 02 03"</param>
		/// <returns></returns>
		[HttpPost]
		[Route("Client/{sessionId}/SendHex")]
		public async Task<IActionResult> SendHex(string sessionId, [FromBody] string sendData)
		{
			return await Task.Run(() => { return Ok(Global.ServerInfoFun.SendHexBySessionId(sessionId, sendData)); });
		}




	}
}
